package org.spring.demo.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.spring.demo.dao.UserDao;
import org.spring.demo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {

	private SessionFactory sessionFactory;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;//
	}

	@Override
	public void addUser(User user) {
		// 省略其他逻辑... 
		sessionFactory.getCurrentSession().save(user);
		
	}

	@Override
	public User findUserByAccount(String account) {
		Session session = sessionFactory.getCurrentSession();
		User user =(User) session.createCriteria(User.class).add(Restrictions.eq("account", account)).uniqueResult();
		return user;
	}
	
	

}
